<template>
  <div>
    <el-empty v-if="dataSource.length === 0" description="暂无快捷菜单" :style="{height: autoHeight }">
      <el-button type="primary" @click="visible = true" icon="el-icon-circle-plus-outline"></el-button>
    </el-empty>
    <el-table v-else v-loading="loading" :data="dataSource" highlight-current-row @row-click="handleRowClick" @row-contextmenu="rightClick" :height="autoHeight">
      <el-table-column prop="quickName" label="快捷菜单" align="center">
        <template slot="header" slot-scope="scope">
          <div>{{ scope.column.label }}</div>
          <el-input  v-model="filterModel[scope.column.property]" :placeholder="scope.column.label + '过滤'" clearable @change="filterChange(scope.column.property)"></el-input>
        </template>
        <template slot-scope="scope">
          <span>{{ scope.row[scope.column.property] }}</span>
          <i v-if="scope.row.appIcon" :class="scope.row.appIcon" style="padding-left: 8px"></i>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="90px">
        <template v-if="!select" slot="header" slot-scope="scope">
          <el-button type="text" @click="visible = true" icon="el-icon-circle-plus-outline"></el-button>
        </template>
        <div slot-scope="scope">
          <template v-if="select">
            <el-button type="success" icon="el-icon-thumb" circle @click="$emit('rowSelect',scope.row)" title="选择"></el-button>
          </template>
          <template v-else>
            <el-button type="text" icon="el-icon-edit" circle @click="() => { entityInfo=$Util.copy(scope.row);visible=true}" title="编辑"></el-button>
            <el-link type="danger" icon="el-icon-delete" circle @click="removeData(scope.row, scope.$index)" title="删除"></el-link>
          </template>
        </div>
      </el-table-column>
    </el-table>
    <div class="lab-table-page">
      <div style="display: inline-flex">
        <el-pagination

            :disabled="loading"
            :current-page="pageInfo.page"
            :page-sizes="[5, 10, 15, 20, 50, 100]"
            :page-size="pageInfo.pageSize"
            layout="total, prev, next"
            :total="pageInfo.total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
        />
        <el-button-group style="padding: 2px 5px">
          <el-button icon="el-icon-refresh" title="刷新" :disabled="loading" @click="loadSource([])" />
        </el-button-group>
      </div>
    </div>
    <el-dialog :visible.sync="visible" title="快捷菜单" width="70%">
      <el-form label-width="80px" label-position="right">
        <el-row :gutter="8">
          <el-col :span="6">
            <el-form-item label="快捷菜单">
              <el-input v-model="entityInfo.quickName" placeholder="菜单名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="快捷菜单">
              <idea-icon v-model="entityInfo.quickIcon" placeholder="菜单图标"></idea-icon>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="快捷视图">
              <el-input disabled v-model="entityInfo.callView" placeholder="渲染视图"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="引用流程">
              <el-input disabled v-model="entityInfo.callProcess" placeholder="引用流程"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label-width="0">
          <div style="text-align: center">
            <el-button icon="el-icon-circle-check" type="success" @click="saveData(entityInfo)">{{ entityInfo.quickId ? '更新' : '保存' }}</el-button>
            <el-button icon="el-icon-circle-close" type="info" @click="visible = false">取消</el-button>
          </div>
          <el-tabs>
            <el-tab-pane label="引用流程">
              <app-process-table select @rowSelect="(row) => { $set(entityInfo, 'callProcess',row.callCmd);$set(entityInfo, 'callView',row.startView)}" />
            </el-tab-pane>
            <el-tab-pane label="引用视图">
              <app-view-table select @rowSelect="(row) => { $set(entityInfo, 'callView',row.callCmd)}"  />
            </el-tab-pane>
          </el-tabs>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import IdeaTable from "@/mixins/IdeaTable";
import AppViewTable from "@/views/system/app/view/AppViewTable";
import IdeaIcon from "@/components/idea-icon/IdeaIcon";
import AppProcessTable from "@/views/system/app/process/AppProcessTable";

export default {
  name: "AppQuickTable",
  components: {AppProcessTable, IdeaIcon, AppViewTable},
  mixins: [IdeaTable],
  inject: {
    appContext: {
      from: 'appContext',
      default: function () {
        return {}
      }
    }
  },
  props: {
    select: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      envTypes: [
        { value: 'db', label: '数据存储' },
        { value: 'store', label: '文件存储' },
        { value: 'prop', label: '属性参数' },
      ]
    }
  },
  created() {
    this.queryUrl = '/appQuick/queryPage'
    this.saveUrl = '/appQuick/save'
    this.removeUrl = '/appQuick/delete/'
    this.rowKey = 'quickId'
    this.pageInfo.pageSize = 20
    this.addFilter({ field: 'appId', op: '=', value: this.appInfo.appId})
    this.loadSource()
  },
  computed: {
    autoHeight() {
      return this.select ? `580px` : `calc(100vh - 398px)`
    }
  },
  methods: {
    selectView(row) {

    }
  }
}
</script>

<style scoped>

</style>
